//
//  MQSaveReadCell.m
//  MQ
//
//  Created by 曾杰 on 15/10/28.
//  Copyright © 2015年 徐永祥. All rights reserved.
//

#import "MQSaveReadCell.h"

@implementation MQSaveReadCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, MQWidth - 80, 30)];
        _contentLabel.font = [UIFont systemFontOfSize:14];
        _contentLabel.numberOfLines = 0;
        [self.contentView addSubview:_contentLabel];
        
        _clearButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_clearButton setImage:[UIImage imageNamed:@"shanchu"] forState:(UIControlStateNormal)];
        _clearButton.frame = CGRectMake(MQWidth - 40, 40, 30, 30);
        [self.contentView addSubview:_clearButton];
    }
    return self;
}
//文字自适应
+ (CGFloat)cellForHeight:(NSString *)string
{
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName];
    CGRect bound = [string boundingRectWithSize:CGSizeMake(MQWidth-80, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return bound.size.height;
}

- (void)cellWithModel:(MQReadCollectionModel *)model{
    _contentLabel.text = model.digest;
    _contentLabel.frame = CGRectMake(10, 10, MQWidth - 80, [MQSaveReadCell cellForHeight:model.digest]);
    _clearButton.frame = CGRectMake(MQWidth - 40, [MQSaveReadCell cellForHeight:model.digest] / 2 , 30, 30);
    
}
+ (CGFloat)HeightForModel:(MQReadCollectionModel *)model{
    if ([self cellForHeight:model.digest] <= 30) {
        return 50;
    }
    return [self cellForHeight:model.digest] + 20;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
